package com.example.schoolexam2.utils;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class fileFormatUtils {
    private static final String FILE_XLS = ".xls";
    private static final String FILE_XLSX = ".xlsx";
    private static final String FILE_JPG = ".jpg";
    private static final String FILE_PNG = ".png";
    private static final String ThePath = "F:\\gitee conle\\kaowu\\src\\main\\resources\\static\\imgs\\student.imgs";

    public static int excelType(MultipartFile file) {
        //获取文件原名
        String Filename = file.getOriginalFilename();
        //获取原名的后缀
        String fileType = Filename.substring(Filename.lastIndexOf("."));
        //判断后缀是否合理，不区分大小写
        if (FILE_XLS.equalsIgnoreCase(fileType)) {
            return 0;
        } else if (FILE_XLSX.equalsIgnoreCase(fileType)) {
            return 1;
        }
        return 2;
    }

    public static Map<String, String> FileName(MultipartFile MultipartFile) {
        Map<String, String> map = null;
        String fileName = MultipartFile.getName();
        if (!(".zip").equalsIgnoreCase(fileName)){
            return null;
        }
        File file = new File(fileName);
        if (file.isDirectory()) {
            // 获取路径下的所有文件
            File[] files = file.listFiles();
            for (int i = 0; i < files.length; i++) {
                String name = files[i].getName();
                String Type = name.substring(name.lastIndexOf("."));
                if (FILE_JPG.equalsIgnoreCase(Type) || FILE_PNG.equalsIgnoreCase(Type)) {

                    String idNumber = name.substring(0, name.lastIndexOf("."));
                    String newThePath = ThePath + name;
                    map.put(idNumber, newThePath);
                }
            }
            return map;
        } else {
            return null;
        }

    }

    public static int ThePathCopy(String lodPath, String newPath, File file) {
        int[] a= {};

        return 0;
    }


}
